package com.example.demo.web;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author xiangyu
 * @Date 2021/12/24 11:10
 * @Version 1.0
 */

@RestController
@RequestMapping("/test")
public class TestController {

    final String UNKNOWN="unknown";

    @GetMapping("/getData")
    public Map getData(HttpServletRequest request){

        String ip1 = request.getHeader("X-Forwarded-For");

        String ip2  = request.getRemoteAddr();

        System.out.println("ip1="+ip1);
        System.out.println("ip2="+ip2);

        Map map=new HashMap();
        map.put("success","1");
        return map;
    }

    @GetMapping("/getData1")
    public Map getData1(HttpServletRequest request) throws Exception{

        String ip1 = request.getHeader("X-Forwarded-For");

        String ip2  = request.getRemoteAddr();

        Thread.sleep(1000*600);

        System.out.println("ip1="+ip1);
        System.out.println("ip2="+ip2);

        Map map=new HashMap();
        map.put("success","1");
        return map;
    }

    @GetMapping("/getData2")
    public Map getData2(HttpServletRequest request){

        String ip1 = request.getHeader("X-Forwarded-For");

        String ip2  = request.getRemoteAddr();


        for (int i=0;i<10000;i++){
            for (int j=0;j<10000;j++){
                System.out.println("ip1="+ip1);
                System.out.println("ip2="+ip2);
            }
        }


        Map map=new HashMap();
        map.put("success","1");
        return map;
    }
}
